var nodemailer = require('nodemailer')
var smtpTransport = require('nodemailer-smtp-transport');

smtpTransport = nodemailer.createTransport({
    host: 'smtp.exmail.qq.com',
    port: 465,
    auth: {
        user: 'yanchengbaohu@archi-motive.com',//自己的QQ邮箱地址
        pass: 'Yancheng123'//使用自己的QQ邮箱申请一个，下边会有详细讲解
    }
});

/**
 * @param {String} receiver 收件人
 * @param {String} subject 发送的主题
 * @param {String} html 发送的html内容
 */
var sendMail = function(receiver, title, content) {

    return new Promise((resolve, reject) => {
        smtpTransport.sendMail({
            from: 'yanchengbaohu@archi-motive.com',
            to: receiver,
            subject: title,
            html: content
        }, (err, response) => {
            if (err) {
                return reject(err)
            }
            resolve(response)
        });
    })
}

module.exports = {
    sendMail
}
